﻿using LumenLiquid.Database;
using LumenLiquid.Database.Entities.World;
using LumenLiquid.Debug;
using LumenLiquid._3D;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using NHibernate;
using DebugLevel = LumenLiquid.Debug.DebugHandler.EDebugLevel;

namespace LumenLiquid.InGame.world
{
    public class Map
    {
        private Model _mapMesh;
        //private Matrix _world;
        Terrain _map = new Terrain();
        private Skybox _skybox = new Skybox();

        public bool Init(int mapId, ISessionFactory worldSession)
        {
            DebugHandler.Log("Initializing map instance...", DebugLevel.Code);

            var session = worldSession.OpenSession();
            MapInfo map = DatabaseInteraction.ReadObject<MapInfo>(session, mapId);
            _mapMesh = Main.Instance.Modelmanager.GetWorldModel(map.Mesh);

            _skybox.Init(map.SkyboxTexture);
            _map.Init();

            DebugHandler.Log("Map instance initialized sucessfully.", DebugLevel.Code);
            return true;
        }

        public void ShutdownTransactions()
        {

        }

        public void Update(GameTime gameTime)
        {
            _skybox.Update(gameTime);
            _map.Update(gameTime);
        }

        public void Draw(GameTime gameTime)
        {
            _skybox.Draw();
            _map.Draw(gameTime);
            //_mapMesh.DrawModel(_world);
        }
    }
}
